<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>新增用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <form class="layui-form layui-form-pane" action="" lay-filter="myForm">
        <input type="hidden" name="id" id="id" value="-1">
        <div class="layui-form-item">
            <label class="layui-form-label required">登录名</label>
            <div class="layui-input-block">
                <input type="text" name="username" id="username"lay-verify="required" lay-reqtext="" placeholder="请输入登录名" value=""
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">登录密码</label>
            <div class="layui-input-block">
                <input type="password" id="password" name="password" lay-verify="required|pass" lay-reqtext="" placeholder="请输入登录密码" value=""
                       class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">登录密码</label>
            <div class="layui-input-block">
                <input type="password" id="password1" name="password1" lay-verify="required|pass" lay-reqtext="" placeholder="请再次输入登录密码" value=""
                       class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色类型</label>
            <div class="layui-input-block">
                <select name="roleId" id="roleId" layui-filter="roleSelect">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </form>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/layutil.js" charset="utf-8"></script>
<script src="https://cdn.bootcss.com/blueimp-md5/2.12.0/js/md5.min.js"></script>
<script>
    layui.use(['form','layer'], function () {
        var form = layui.form,
            $ = layui.$;
        //查询角色类型
        layutil.post('/myerp/role/all', null, function (res) {
            var roles = res.data;
            console.log("roles", roles);
            for(var o in roles) {
                var role = roles[o];
                $("#roleId").append("<option value=\""+role["id"]+"\">"+role["cname"]+"</option>")
            }
            form.render('select');
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var psw = $("#password").val();
            var psw1 = $("#password1").val();
            if(psw != psw1) {
                layutil.fail("两次密码输入不一致！", 3);
                return false;
            }
            var str = "确定新增？";
            layutil.confirm(str, function () {
                var param = {
                    id:$("#id").val(),
                    username:$("#username").val(),
                    password:$("#password").val(),
                    roleId:$("#roleId").val()
                };
                layutil.postForm("/myerp/user/save",param);
            });
            return false;
        });

    });
</script>
</body>
</html>